﻿using PBO.Data.Rnd;
using PBO.Data.Rom;
using PBO.Data.SQLite;
using PBO.Data.Util;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using PBO.Data.Domain;

namespace PBO.Data
{
    public static class GameService
    {
        private const string IMG_FILE = "images.pgd";
        private static ImageService image;

        static GameService()
        {
            Load(AppDomain.CurrentDomain.BaseDirectory);
        }

        private static bool Load(string dir)
        {
            string imgfile = Path.Combine(dir, IMG_FILE);

            try
            {
                image = new ImageService();
                image.LoadData(imgfile);
            }
            catch
            {
                return false;
            }
            return true;
        }

        #region funtion

        public static Bitmap GetImage(int identity, long position)
        {
            return image.GetImage(position);
        }

        public static MoveData GetMove(int id)
        {
            return SQLiteHelper.MoveData.GetModel(id) ?? MoveData.Empty;
        }

        public static PokemonData GetPokemon(int id)
        {
            return SQLiteHelper.Pokemon.GetModel(id);
        }

        public static TeamData GetRandomTeam(Random random)
        {
            return RandomData.GetSmogonTeam(random);
        }

        public static List<PokemonData> GetAllPokemons()
        {
            return SQLiteHelper.Pokemon.GetAllPokemon();
        }

        public static void PokemonCounter(int pid)
        {
            SQLiteHelper.Pokemon.CounterAdd(pid);
        }

        #endregion

        #region Ability
     
        public static Ability GetAbility(int id)
        {
            return SQLiteHelper.Ability.GetModel(id);
        }

        public static Ability GetAbility(Trait trait)
        {
            return GetAbility((int)trait);
        }

        #endregion

        #region item data

        public static ItemData GetItem(int id)
        {
            return SQLiteHelper.Item.GetModel(id);
        }

        public static ItemData GetItem(Item item)
        {
            return GetItem((int)item);
        }

        #endregion

    }
}